/*
 * Created on 2005-1-25
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.nauu.atombuilder.util;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.gef.palette.CombinedTemplateCreationEntry;
import org.eclipse.gef.palette.ConnectionCreationToolEntry;
import org.eclipse.gef.palette.PaletteContainer;
import org.eclipse.gef.palette.PaletteDrawer;
import org.eclipse.gef.palette.PaletteGroup;
import org.eclipse.gef.palette.PaletteRoot;
import org.eclipse.gef.palette.SelectionToolEntry;
import org.eclipse.gef.palette.ToolEntry;
import org.eclipse.gef.requests.CreationFactory;
import org.eclipse.gef.requests.SimpleFactory;
import org.eclipse.jface.resource.ImageDescriptor;

import com.nauu.atombuilder.AtomBuilderPlugin;
import com.nauu.atombuilder.modle.Connection;
import com.nauu.atombuilder.modle.Dialog;
import com.nauu.atombuilder.modle.Form;
import com.nauu.atombuilder.modle.Grid;

/**
 * @author nauu
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class PaletteFactory {
    public static PaletteRoot createPalette() {
        PaletteRoot paletteRoot = new PaletteRoot();
        paletteRoot.addAll(createCategories(paletteRoot));
        return paletteRoot;
    }

    private static List createCategories(PaletteRoot root) {
        List categories = new ArrayList();

        categories.add(createControlGroup(root));
        categories.add(createComponentsDrawer());

        return categories;
    }

    private static PaletteContainer createControlGroup(PaletteRoot root) {
        PaletteGroup controlGroup = new PaletteGroup("Control Group");

        List entries = new ArrayList();
        ToolEntry tool = new SelectionToolEntry();
        entries.add(tool);
        root.setDefaultEntry(tool);

//        tool = new ConnectionCreationToolEntry("connection", "创建一个连接", null, ImageDescriptor.createFromFile(AtomBuilderPlugin.class,"icons/L.png"), null);
//        entries.add(tool);

        tool = new ConnectionCreationToolEntry("track按钮", "创建一个路径按钮", new CreationFactory() {
        	@Override
        	public Object getObjectType() {
        		return Connection.TRACK;
        	}
        	@Override
        	public Object getNewObject() {
        		return null;
        	}
        }, ImageDescriptor.createFromFile(AtomBuilderPlugin.class,"icons/t.png"), null);
        entries.add(tool);
        tool = new ConnectionCreationToolEntry("clip按钮", "创建一个剪切板按钮", new CreationFactory() {
        	@Override
        	public Object getObjectType() {
        		return Connection.CLIP;
        	}
        	@Override
        	public Object getNewObject() {
        		return null;
        	}
        }, ImageDescriptor.createFromFile(AtomBuilderPlugin.class,"icons/c.png"), null);
        entries.add(tool);
        tool = new ConnectionCreationToolEntry("grid按钮", "创建一个Grid按钮", new CreationFactory() {
        	@Override
        	public Object getObjectType() {
        		return Connection.GRID;
        	}
        	@Override
        	public Object getNewObject() {
        		return null;
        	}
        }, ImageDescriptor.createFromFile(AtomBuilderPlugin.class,"icons/g.png"), null);
        entries.add(tool);

        controlGroup.addAll(entries);
        return controlGroup;
    }

    private static PaletteContainer createComponentsDrawer() {

        PaletteDrawer drawer = new PaletteDrawer("Components");

        List entries = new ArrayList();
        
        ToolEntry grid = new CombinedTemplateCreationEntry("Grid", "Create a new Grid", Grid.class, new SimpleFactory(
                Grid.class), ImageDescriptor.createFromFile(AtomBuilderPlugin.class,"icons/grid.png"), null);
        
        ToolEntry form = new CombinedTemplateCreationEntry("Form", "Create a new Form", Form.class, new SimpleFactory(
                Form.class), ImageDescriptor.createFromFile(AtomBuilderPlugin.class,"icons/form.png"), null);
        
        ToolEntry dialog = new CombinedTemplateCreationEntry("Dialog", "Create a new Dialog", Dialog.class, new SimpleFactory(
        		Dialog.class), ImageDescriptor.createFromFile(AtomBuilderPlugin.class,"icons/dialog.png"), null);
        entries.add(grid);
        entries.add(form);
        entries.add(dialog);

        drawer.addAll(entries);
        return drawer;
    }
}